package com.zhixiang.xaec.service.safebase.safecultruetrain.impl;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.zhixiang.core.dao.BaseDao;
import com.zhixiang.core.service.impl.BaseServiceImpl;
import com.zhixiang.core.util.EChartUtils;
import com.zhixiang.xaec.dao.safebase.safecultruetrain.CultureActivityDao;
import com.zhixiang.xaec.entity.safebase.safecultruetrain.CultureActivity;
import com.zhixiang.xaec.service.safebase.safecultruetrain.CultureActivitySheetService;

@ Service
 public class CultureActivitySheetServiceImpl extends BaseServiceImpl<CultureActivity,Long> implements CultureActivitySheetService {
      
	
	  @Resource(type=CultureActivityDao.class)
	  @Override
	  public void setBaseDao(BaseDao<CultureActivity, Long> dao) {
		        setDao(dao);
		 
	  }
	
	  public String getChartByFtl() {
        Map<String, Object> rootMap = new HashMap<String, Object>();
        List<CultureActivity> list=getDao().findByHql("From CultureActivity ",new Object[]{});
        Set<Integer> yearSet =new HashSet<Integer>();
        for(CultureActivity o :list){
        	Integer years=Integer.parseInt(o.getYears());
        	yearSet.add(years);
        }
        List<Integer>yearList=new ArrayList<Integer>(yearSet);
        Collections.sort(yearList);
        List<Double> foundsList =new ArrayList<Double>();
        for(int i=0;i<yearList.size();i++){
        double sum=0;	
        for(CultureActivity founds :list){
         if(Integer.parseInt(founds.getYears())==yearList.get(i)){
        	sum+=(double)founds.getActivityfunds();
        }
        }
        foundsList.add(sum);
        }
        rootMap.put("dataList", yearList);
        rootMap.put("foundsList", foundsList);
        return EChartUtils.getChart(rootMap, "chart_cultureActivity");
    }





}
